/*
** accept_client.c for  in /home/faye_m//tmp/zappy-2011/new_server/src/zappy-2011/new_server/src
** 
** Made by mouhamed faye
** Login   <faye_m@epitech.net>
** 
** Started on  Sun Jul 10 12:25:49 2011 mouhamed faye
** Last update Sun Jul 10 12:32:47 2011 mouhamed faye
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
#include "types.h"

int	    accept_client(T_env *e)
{
  e->addrlen = sizeof(e->clientaddr);
  if ((e->newfd = accept(e->listener, (struct sockaddr *)&e->clientaddr,
			&e->addrlen)) == -1)
    perror("Server-accept() !");
  else
    {
      FD_SET(e->newfd, &e->master);
      if (e->newfd > e->fdmax)
        e->fdmax = e->newfd;
      printf("New connection from %s on socket %d\n Sending Bienvenue %d\n",
	 inet_ntoa(e->clientaddr.sin_addr), e->newfd, e->newfd);
      send(e->newfd, "Bienvenue\n", 10, 0);
      e->first_cmd = TRUE;
    }
  return (1);
}
